package com.jt.provider.controller;

import lombok.extern.slf4j.Slf4j;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.logging.Logger;
//@RefreshScope //假如希望配置中心内容发生变化,要对此类中属性进行初始化,
//可使用此注解@RefreshScope对类进行描述,这个注解描述类时,
//一旦配置中心的内容发生了变化,而此类中的有些属性的值又需要配置中心读取,此时
//再次访问数据时,@RefreshScope注解描述的类的对象就会重新创建.
@Slf4j
@RestController
public class ProviderLogController {
    public ProviderLogController(){
        System.out.println("==ProviderLogController()==");
    }
    //private static Logger log =
    // LoggerFactory.getLogger(ProviderLogController.class);
    @GetMapping("/provider/log/doLog01")
    public String daLo01(){//日志级别:treace<debug<info<warn<error
        System.out.println("==log01==");
        log.trace("==trace==");
        log.debug("==debug==");
        log.info("==info==");
        log.warn("==warn==");
        log.error("==error==");
        return "log config test";
    }
    //定义一个日志级别属性,用于存储从配置文件或配置中心读取的数据
    @Value("${logging.level.com.jt:error}")
    private String logLevel;//属性会在构建对象时初始化
    @GetMapping("/provider/log/doLog02")
    public String doLog02(){
        log.info("log level is  {}",logLevel);
        return  "log level  is "+logLevel;
    }

}
